package com.soso.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name="users")
public class Users {
	
	@Id
     @Column(name="Id",length = 350)
	private String Id;

	
	private String LoginName;
	 
	private String Password;
	private String IsLockout;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	private Date LastLoginTime;
	private Integer PsdWrongTime;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	private Date LockTime;
	private String ProtectEMail;
	private String protectMTel;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	private Date CreateTime;
	 @JsonIgnoreProperties("users")
	@ManyToMany(targetEntity = Roles.class,fetch = FetchType.EAGER)//即时加载
	            //指定第三张表的名称                   //指定在中间表中与id的对应关系
	@JoinTable(name="userroles",joinColumns = {@JoinColumn(name="UserId")},
	//另一张表的主键与中间表的对应关系
	inverseJoinColumns = {@JoinColumn(name="RoleId")})
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Roles> roles=new ArrayList<Roles>();
	 
	public String getId() {
		return Id;
	}
	public void setId(String id) {
		Id = id;
	}
	public List<Roles> getRoles() {
		return roles;
	}
	public void setRoles(List<Roles> roles) {
		this.roles = roles;
	}
	public String getLoginName() {
		return LoginName;
	}
	public void setLoginName(String loginName) {
		LoginName = loginName;
	}
	public String getPassword() {
		return Password;
	}
	public void setPassword(String password) {
		Password = password;
	}
	public String getIsLockout() {
		return IsLockout;
	}
	public void setIsLockout(String isLockout) {
		IsLockout = isLockout;
	}
	public Date getLastLoginTime() {
		return LastLoginTime;
	}
	public void setLastLoginTime(Date lastLoginTime) {
		LastLoginTime = lastLoginTime;
	}
	public Integer getPsdWrongTime() {
		return PsdWrongTime;
	}
	public void setPsdWrongTime(Integer psdWrongTime) {
		PsdWrongTime = psdWrongTime;
	}
	public Date getLockTime() {
		return LockTime;
	}
	public void setLockTime(Date lockTime) {
		LockTime = lockTime;
	}
	public String getProtectEMail() {
		return ProtectEMail;
	}
	public void setProtectEMail(String protectEMail) {
		ProtectEMail = protectEMail;
	}
	public String getProtectMTel() {
		return protectMTel;
	}
	public void setProtectMTel(String protectMTel) {
		this.protectMTel = protectMTel;
	}
	public Date getCreateTime() {
		return CreateTime;
	}
	public void setCreateTime(Date createTime) {
		CreateTime = createTime;
	}
	public Users(String id, List<Roles> roles, String loginName, String password, String isLockout, Date lastLoginTime,
			Integer psdWrongTime, Date lockTime, String protectEMail, String protectMTel, Date createTime) {
		super();
		Id = id;
		this.roles = roles;
		LoginName = loginName;
		Password = password;
		IsLockout = isLockout;
		LastLoginTime = lastLoginTime;
		PsdWrongTime = psdWrongTime;
		LockTime = lockTime;
		ProtectEMail = protectEMail;
		this.protectMTel = protectMTel;
		CreateTime = createTime;
	}
	public Users() {
		super();
	}
	@Override
	public String toString() {
		return "Users [Id=" + Id + ", LoginName=" + LoginName + ", Password=" + Password + ", IsLockout=" + IsLockout
				+ ", LastLoginTime=" + LastLoginTime + ", PsdWrongTime=" + PsdWrongTime + ", LockTime=" + LockTime
				+ ", ProtectEMail=" + ProtectEMail + ", protectMTel=" + protectMTel + ", CreateTime=" + CreateTime
				+ ", roles=" + roles + "]";
	}







	
}
